﻿using System.Windows.Controls;
using System.Windows;

namespace a21_RoutedEvent
{
    public class MyButton : Button
    {
        public static readonly RoutedEvent MyClickEvent = EventManager.RegisterRoutedEvent(
            "MyClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyButton));

        public event RoutedEventHandler MyClick
        {
            add { AddHandler(MyClickEvent, value); }
            remove { RemoveHandler(MyClickEvent, value); }
        }

        private void RaiseMyClickEvent()
        {
            var evtArg = new RoutedEventArgs(MyClickEvent);
            RaiseEvent(evtArg);
        }

        protected override void OnClick()
        {
            //base.OnClick();
            RaiseMyClickEvent();
        }
    }
}
